package kr.co.boogui.helper;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/image.bi")
public class Image extends HttpServlet {
	private static final long serialVersionUID = 1L;
//	private String fpath = "D:/cdn/boogui/";
	private String fpath = "/home/hosting_users/kimuno/CDN/boogui/";
	protected void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		String myImg = fpath + req.getParameter("id");
		
		res.setContentType("image/jpeg");
		InputStream in = null;
		OutputStream out = null;
		try {
			in = new FileInputStream(myImg);
			out = res.getOutputStream();

			int read = 0;
			final byte[] bytes = new byte[1024];
			while ((read = in.read(bytes)) != -1) {
				out.write(bytes, 0, read);
			}

		} catch (FileNotFoundException fne) {
			fne.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
			if (in != null) {
				in.close();
			}
		}

	}

}
